/*
 * Pesec.java
 *
 * Created on 18. �erven 2007, 20:31
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package cz.possoft.serializable.chess.figurky;

import cz.possoft.generic.utils.GenericUtils;
import cz.possoft.messages.PropertiesManager;
import cz.possoft.messages.Text;
import cz.possoft.serializable.chess.game.ChessPole;

/**
 *
 * @author mara
 */
public class Pesec extends Figurka {
	
	public static final long serialVersionUID = 100458799;
	
    /** Creates a new instance of Pesec */
    public Pesec(int x,int y,int color,ChessPole sachovnice) {
        setX(x);
        setY(y);
        setColor(color);
        setSachovnice(sachovnice);
        setMarked(false);
    }
    
    public String getFigurkaName() {
        return PropertiesManager.getInstance().getMessageForKey(Text.PESEC);
    }
    
    public boolean muzeTahnout2(int xCil,int yCil) {
        if ((xCil<0)||(xCil>7)||(yCil<0)||(yCil>7)) return false;
          
          if (getColor() == GenericUtils.COLOR_WHITE) {
              if ((xCil == getX()) && (yCil - getY() == -1) && (getSachovnice().getFigurka(xCil, yCil).getColor() == GenericUtils.COLOR_NEUTRAL)) return true;
              if ((getY() == 6) && (xCil == getX()) && (yCil == 4) && (getSachovnice().getFigurka(xCil, 5).getColor() == GenericUtils.COLOR_NEUTRAL) && (getSachovnice().getFigurka(xCil, yCil).getColor() == GenericUtils.COLOR_NEUTRAL)) return true;
              if ((GenericUtils.abs(getX() - xCil) == 1) && (yCil - getY() == -1) && (getSachovnice().getFigurka(xCil, yCil).getColor() == GenericUtils.COLOR_BLACK)) return true;
          }
          if (getColor() == GenericUtils.COLOR_BLACK) {              
              if ((xCil == getX()) && (yCil - getY() == 1) && (getSachovnice().getFigurka(xCil, yCil).getColor() == GenericUtils.COLOR_NEUTRAL)) return true;
              if ((getY() == 1) && (xCil == getX()) && (yCil == 3) && (getSachovnice().getFigurka(xCil, yCil).getColor() == GenericUtils.COLOR_NEUTRAL) && (getSachovnice().getFigurka(xCil, 2).getColor() == GenericUtils.COLOR_NEUTRAL)) return true;
              if ((GenericUtils.abs(getX() - xCil) == 1) && (yCil - getY() == 1) && (getSachovnice().getFigurka(xCil, yCil).getColor() == GenericUtils.COLOR_WHITE)) return true;
          }
       //System.out.println("MuzeTahnout u pesce: " + xCil + " " + yCil);       
        // kontrola en passant
        if (((getColor() == 1) && (getY() == 4)) || ((getColor() == 2) && (getY() == 3))) {
            int[] lastTah = getSachovnice().getLastTah();
            //System.out.println("LastTah: " + lastTah[0] + " " + lastTah[1] + " " + lastTah[2] + " " + lastTah[3]);       
            if (xCil != 0) {
                Figurka pomPesec = getSachovnice().getFigurka(xCil - 1, yCil);                
                //System.out.println((pomPesec instanceof Pesec) + " " + (pomPesec.getColor() != getColor()) + ((getColor() == 1) && (lastTah[0] == xCil ) && (lastTah[1] == 6) && (lastTah[2] == xCil ) && (lastTah[3] == yCil)) + " " + 
              //         ((getColor() == 2) && (lastTah[0] == xCil ) && (lastTah[1] == 1) && (lastTah[2] == xCil ) && (lastTah[3] == yCil)) ) ;
                if ((pomPesec instanceof Pesec) && 
                   (((getColor() == 1) && (lastTah[0] == xCil ) && (lastTah[1] == 6) && (lastTah[2] == xCil ) && (lastTah[3] == yCil)) || 
                   ((getColor() == 2) && (lastTah[0] == xCil ) && (lastTah[1] == 1) && (lastTah[2] == xCil ) && (lastTah[3] == yCil)))) return true;
            }
            if (xCil != 7) {
                Figurka pomPesec = getSachovnice().getFigurka(xCil + 1, yCil);                
                //System.out.println((pomPesec instanceof Pesec) + " " + (pomPesec.getColor() != getColor()) + ((getColor() == 1) && (lastTah[0] == xCil ) && (lastTah[1] == 6) && (lastTah[2] == xCil ) && (lastTah[3] == yCil)) + " " + 
                //       ((getColor() == 2) && (lastTah[0] == xCil ) && (lastTah[1] == 1) && (lastTah[2] == xCil ) && (lastTah[3] == yCil)) ) ;
                if ((pomPesec instanceof Pesec) &&  
                   (((getColor() == 1) && (lastTah[0] == xCil ) && (lastTah[1] == 6) && (lastTah[2] == xCil ) && (lastTah[3] == yCil)) || 
                   ((getColor() == 2) && (lastTah[0] == xCil ) && (lastTah[1] == 1) && (lastTah[2] == xCil ) && (lastTah[3] == yCil)))) return true;
            }
        }
        return false;
    }
    
}
